package com.rsxy.service.tools;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rsxy.service.pojo.RsImage;
import com.rsxy.service.service.RsImageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;


@Slf4j
public class SchedulUtil {

    @Autowired
    private RsImageService rsImageService;
    @Scheduled(cron = "0/60 * * * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void configureTasks() {
        List<String> list = QiNiuUtil.getList();
        if (list.size()>0){
            for (String s : list) {
                QueryWrapper<RsImage> queryWrapper=new QueryWrapper<>();
                queryWrapper.eq("img_key",s);
                RsImage rsImage = rsImageService.getBaseMapper().selectOne(queryWrapper);
                if (rsImage==null){
                    Boolean rsxy_image = QiNiuUtil.deleteFile("rsxy_image", s);
                    log.info("垃圾图片:"+s+",删除状态:"+rsxy_image);
                }
            }
            log.info("垃圾文件已清理完毕~");
        }
    }
}
